package 力扣日常刷题.木23一月.第11天311;

import 力扣日常刷题.TreeNode;

/**
 * @author 帅小伙
 * @date 2022/3/11
 * @description
 */
public class Demo42树的子结构 {

    public boolean isSubStructure(TreeNode A, TreeNode B) {
        return (A != null && B != null) &&
                (solution(A,B)||
                        isSubStructure(A.left,B)||
                        isSubStructure(A.right, B));
    }

    public boolean solution(TreeNode A, TreeNode B) {
        if(B ==null) return true;
        if(A == null || A.val != B.val) return false;
        return solution(A.right, B.right) && solution(A.left,B.left);
    }

}
